from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
from hbase.ttypes import *

transport = TSocket.TSocket('analysis-01', 9090);
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport);

client = Hbase.Client(protocol)
transport.open()

tableName = 'testBase'


# 创建表操作
# contents = ColumnDescriptor(name='cf:', maxVersions=1)
# client.createTable('TestBase', [contents])
# print(client.getTableNames())

# 给表添加数据
row = 'row-key2'
mutations = [Mutation(column="cf:a", value="1a")]
client.mutateRow(tableName, row, mutations)

# 获取一行值 这个在3.4不行  得放到2.7
result = client.getRow(tableName,row)
print(result)
# for i in result:
#     print(i.row)
#     print(i.columns)


